package com.threeox.commonlibrary.ui.view.multipagenavigation;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.threeox.commonlibrary.ui.view.inter.IPageDataView;
import com.threeox.commonlibrary.util.ViewUtils;
import com.threeox.utillibrary.util.res.LayoutParamsUtils;
import com.threeox.utillibrary.util.res.LayoutUtils;

/**
 * 
 * @ClassName: PageDataView
 * 
 * @Description: TODO(多页面网络的子页面View)
 * 
 * @author 赵屈犇
 * 
 * @date 创建时间: 2017/10/23 17:13
 * 
 * @version 1.0
 * 
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class CommonPageDataView extends LinearLayout implements IPageDataView {

    protected ViewUtils mViewUtils;
    protected LayoutParamsUtils layoutParamsUtils;

    public CommonPageDataView(Context context) {
        this(context, null);
    }

    public CommonPageDataView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CommonPageDataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mViewUtils = ViewUtils.newInstance();
        this.layoutParamsUtils = LayoutParamsUtils.newInstance(getContext());
    }

    /**
     * 设置布局
     *
     * @param layoutId
     * @param data
     */
    @Override
    public void setLayout(Integer layoutId, Object data) {
        try {
            LayoutUtils.inflate(getContext(), layoutId, this);
            mViewUtils.inJectViewByTag(data, this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
